<?php
/**
 * @version		$Id: article.php 7324 2007-05-03 20:26:02Z louis $
 * @package		Joomla
 * @subpackage	calendar
 * @copyright	Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport('joomla.application.component.model');

/**
 * calendar Component Article Model
 *
 * @author	Louis Landry <louis.landry@joomla.org>
 * @package		Joomla
 * @subpackage	calendar
 * @since 1.5
 */
class calendarModelXml extends JModel
{
	 var $_data;
	 var $_buildtype;
	 //var_dump('here');
	 
	 function _setBuild($type = 'Calendar')
    {
		$this->_buildtype = "_build".ucfirst($type);
		//var_dump($this->_buildtype);
		return "_build".ucfirst($type);
	}
	 
    function _buildCalendar()
    {
        $query = 'SELECT a.id, a.title, a.event_start, a.description, a.catid  FROM #__calendar AS a INNER JOIN #__categories AS c ON a.catid = c.id WHERE a.published = 1 ORDER BY a.catid, a.event_start' ;
        return $query;
    }
	
	function _buildDetail()
    {
		$whereId = (empty($this->_id)) ? '' : 'and a.id="'.$this->_id.'"' ;
        $query = 'SELECT a.id, a.title, a.event_start, a.description, a.catid  FROM #__calendar AS a INNER JOIN #__categories AS c ON a.catid = c.id WHERE a.published = 1 '.$whereId.' ORDER BY a.catid, a.event_start' ;
        return $query;
    }

    /**
     * Retrieves the hello data
     * @return array Array of objects containing the data from the database
     */
    function getData()
    {
        // Lets load the data if it doesn't already exist
        if (empty( $this->_data ))
        {
			if(empty($this->_buildtype)){
				$type = $this->_setBuild();
			}else{
				$type = $this->_buildtype;
			}
			//var_dump($type);
            $calendar = $this->$type();//$this->_buildCalendar();////$this->_build$type();
            $this->_data = $this->_getList( $calendar );
        }
		
		return $this->_data;
		
    }
}
